package com.chixing.controller;

import com.chixing.pojo.Customer;
import com.chixing.service.BudingSetService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class BudingSetController {
    @Autowired
    private BudingSetService budingSetService;
    @GetMapping("customer/customermain")
    public ModelAndView getById( HttpSession httpSession){
        Customer customer = (Customer) httpSession.getAttribute("loginCustomer");
        ServerResponse serverResponse=budingSetService.getById(customer.getCustId());
        ModelAndView mav=new ModelAndView();
        mav.addObject("serverResponse",serverResponse);
        mav.setViewName("customer/binding_set");
        return mav;
    }

    @PutMapping("customer/binding_set")
    public ModelAndView update(Integer custId,String custEmail,String custName,String custIdcard){
        System.out.println(custId);
        ServerResponse serverResponse1=budingSetService.update(custId,custEmail,custName,custIdcard);

        ModelAndView mav=new ModelAndView();
        if (serverResponse1.getCode()==200){
            System.out.println(serverResponse1);
            ServerResponse serverResponse=budingSetService.getByCustId(custId);
            mav.addObject("serverResponse",serverResponse);
            mav.setViewName("customer/binding_set_detail");
//            mav.setViewName("index");
        }else {
            mav.addObject("responseMsg","绑定失败");
        }
        return mav;
    }
}
